<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/login.css" />
		<link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_546019_0ch5uh619edk7qfr.css" />
		<title>注册</title>
		<script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/city-picker.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style type="text/css">
		.li1,.li2,.li3,.li4{
			margin-top: 0 !important;
		}
	</style>
	<body>
		<!--<div id="header">
			<div class="header-title" style="position: fixed;top: 0;border-bottom: 0;">
				<img src="../../img/left.png" class="left" />
				<span>注册</span>
			</div>
		</div>-->
		<div class="registerSecond" style="margin-top: 0;">
			<form action="" method="post" id="form1">
				<div class="enterprise">
					<div class="identity-type">
						<span>企业（必填）</span>
					</div>
					<div class="type1">
						<div class="name">
							<span>证件类型</span>
							<span>三证合一</span>
						</div>
						<ul class="img-warp img-warp2">
							<li class="li1">
								<input type="file" id="img1" name="" class="upload_pic upload" />
								<canvas class="cvs" id="cvs1" width="100" height="100"></canvas>
								<img id="pic1" src="../../img/photo.png" />
								<span>营业执照</span>
							</li>
						</ul>
					</div>
					<!--img_business_license,img_organization_code,img_duty,img_idcard_zheng,img_idcard_fan-->
					<div class="type2">
						<div class="name">
							<span>证件类型</span>
							<span>三证</span>
						</div>
						<ul class="img-warp ">
							<li class="li2">
								<input type="file" id="img2" name="" class="upload_pic upload" />
								<canvas class="cvs" id="cvs2" width="100" height="100"></canvas>
								<img id="pic2" src="../../img/photo.png" />
								<span>营业执照</span>
							</li>
							<li class="li3">
								<input type="file" id="img3" name="" class="upload_pic upload" />
								<canvas class="cvs" id="cvs3" width="100" height="100"></canvas>
								<img id="pic3" src="../../img/photo.png" />
								<span>组织机构代码证</span>
							</li>
							<li class="li4">
								<input type="file" id="img4" name="" class="upload_pic upload" />
								<canvas class="cvs" id="cvs4" width="100" height="100"></canvas>
								<img id="pic4" src="../../img/photo.png" />
								<span>税务登记证</span>
							</li>
						</ul>
					</div>

				</div>
				<div class="personal">
					<div class="identity-type">
						<span>个人/法人身份证（必填）</span>
					</div>
					<ul class="img-warp">
						<li class="li5">
							<input type="file" id="img5" name="" class="upload_pic upload" />
							<canvas class="cvs" id="cvs5" width="100" height="100"></canvas>
							<img id="pic5" src="../../img/photo.png" />
							<span>身份证正面</span>
						</li>
						<li class="li6">
							<input type="file" id="img6" name="" class="upload_pic upload" />
							<canvas class="cvs" id="cvs6" width="100" height="100"></canvas>
							<img id="pic6" src="../../img/photo.png" />
							<span>身份证反面</span>
						</li>
					</ul>

				</div>
				<div class="demos-content-padded" style="margin-bottom:1.2rem ;">
					<a href="javascript:;" class="weui-btn weui-btn_primary">确定</a>
				</div>
			</form>
		</div>
	</body>
	<script type="text/javascript">
		$(document).ready(function(){
			baseConfig.historyBack()
			var type1 = baseConfig.GetQueryString("type");
			var type2 = baseConfig.GetQueryString("type2");
			if(type1 == 0) {
				$('.enterprise').show()
				if(type2 == 1) {
					$(".type2").hide()
					$(".type1").show()
				} else {
					$(".type2").show()
					$(".type1").hide()
				}
			} else {
				$('.enterprise').hide()
				$(".personal").show()
			}
			//图片上传部分		
//			for(var i = 0; i < $(".shooseimg").length; i++) {
//				$(".shooseimg").eq(i).on("click", function() {
//					var index = $(this).index()
//					chooseImg(index)
//				})
//			}
			// 允许上传的图片类型
			var allowTypes = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'];
			// 1024KB，也就是 1MB
			var maxSize = 1024 * 1024;
			// 图片最大宽度
			var maxWidth = 300;
			// 最大上传图片数量
			var maxCount = 1;

			$('#img1').on('change', function(event) {
				chooseImg(event, "img1", "cvs1", "img_business_license", "pic1")
			})
			$('#img2').on('change', function(event) {
				chooseImg(event, "img2", "cvs2", "img_business_license", "pic2")
			})
			$('#img3').on('change', function(event) {
				chooseImg(event, "img3", "cvs3", "img_organization_code", "pic3")
			})
			$('#img4').on('change', function(event) {
				chooseImg(event, "img4", "cvs4", "img_duty", "pic4")
			})
			$('#img5').on('change', function(event) {
				chooseImg(event, "img5", "cvs5", "img_idcard_zheng", "pic5")
			})
			$('#img6').on('change', function(event) {
				chooseImg(event, "img6", "cvs6", "img_idcard_fan", "pic6")
			})

			function chooseImg(event, name, name2, name3, name4) {
				var files = event.target.files;
				// 如果没有选中文件，直接返回
				if(files.length === 0) {
					return;
				}
				var input1 = document.getElementById(name)
				input1.setAttribute("name", "file")
				var file = files[0];
				var reader = new FileReader();
				// 如果类型不在允许的类型范围内
				reader.onload = function(e) {
					var img = new Image();
					img.onload = function() {
						var canvas = document.getElementById(name2);
						var ctx = canvas.getContext("2d");
						ctx.clearRect(0, 0, canvas.width, canvas.height);
						ctx.drawImage(img, 0, 0, 100, 100);
						var imgPic = document.getElementById(name4)
						imgPic.style.display = "none"
						imgPic.setAttribute("data-img","true")
						var formData = new FormData($("#form1")[0])
						formData.append("clientNo", baseConfig.GetQueryString("clientNo"));
						formData.append("imgType", name3)
						input1.setAttribute("name", "")
						$.ajax({
							type: "post",
							url: baseConfig.localHttp + "api/client/uploadClientImg",
							data: formData,
							contentType: false,
							processData: false,
							success: function(data){
								if(data.code == 100) {

								} else {

								}
							},
							error: function() {
								$.hideLoading();
								$.toast("请求失败", "cancel");
							}
						})
					};
					img.src = e.target.result;
				};
				reader.readAsDataURL(file);
			}
			//提交
			$(".weui-btn").on("click", function() {
				if(($("#pic5").attr("data-img")=="true") && ($("#pic6").attr("data-img")=="true")){
					location.href = "login.html"
				}else{
					
				}
			})
		})
	</script>

</html>